#!/usr/bin/perl
#act_sscreate.cgi
require './lvm-lib.pl';
&ReadParse();
my ($vgname, $err_msg, $lvname, $vgfree, $size);

$lv = $in{'origlv'};
$snapname = $in{'snapname'};
$minsize = $in{'minsize'};
$maxsize = $in{'maxsize'};
$unit = $in{'unit'};
$size = $in{'lvsize'};
if($size =~ /[^.0-9]/){
	$err_msg = $text{'invalid_size_format'};
	goto ERROR_OUT;
}
if($unit =~ /GB/){
	$size = $size * 1024;
}
elsif($unit =~ /MB/){
	$size = $size;	
}
my $lvsize = $size."M";

$err_msg = "$lv|$snapname|$minsize|$maxsize|$size";
#goto ERROR_OUT;
if(($size < $minsize) || ($size > $maxsize)){
	$err_msg = $text{'ss_size_invalid'};
	goto ERROR_OUT;
}
my $rc;
$rc = `lvm lvcreate -s -L $lvsize -n $snapname $lv 2>/dev/null`;
if($rc =~ /created/){
	&redirect("snapshot.cgi?lv=$lv");
}else{
	$err_msg = $text{'err_createss'};
	goto ERROR_OUT;
}
return;
ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);
